<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改密码</title>
<script type="text/javascript" src="${res}js/MD5.js"></script>
</head>
<body>
	<table id="baseForm">
		<tr>
            <th width="100"><i class="require-red">*</i>原密码：</th>
            <td id="oldPswd">
            	<input type="password" 
						name="oldPswd" 
						msgId="oldPswdMsg"
						rules="[
							{rule:{notNull:true},errorMsg:'不能为空'}
							,{rule:{minLength:6,maxLength:16},successMsg:'√',errorMsg:'密码长度必须为6~16'}
						]"
						data-rules="{required:true,minlength:5,maxlength:20}"
						class="control-text">
            </td>
            <td id="oldPswdMsg"></td>
        </tr>
        <tr>
            <th><i class="require-red">*</i>新密码：</th>
            <td id="newPswd">
            	<input id="newPswdInput" type="password"
						name="newPswd" 
						msgId="newPswdMsg"
						rules="[
							{rule:{notNull:true},errorMsg:'不能为空'}
							,{rule:{minLength:6,maxLength:16},successMsg:'√',errorMsg:'密码长度必须为6~16'}
						]"
						class="control-text"></td>
             <td id="newPswdMsg"></td>
        </tr>
        <tr>
            <th><i class="require-red">*</i>确认新密码：</th>
            <td id="newPswd2">
            	<input type="password"
						name="newPswd2" 
						msgId="newPswd2Msg"
						rules="[
							{rule:{notNull:true},successMsg:'√',errorMsg:'不能为空'}
							,{validateHandler:compareSamePswd,successMsg:'√',errorMsg:'两次密码不一致'}
						]"
						class="control-text">
            </td>
             <td id="newPswd2Msg"></td>
        </tr>
        <tr>
             <th></th>
             <td colspan="2">
                 <button id="btnUpdate" type="button" class="button button-primary">修改</button>
				 <button id="btnCancel" type="button" class="button">取消</button>
             </td>
         </tr>
	</table>
<script type="text/javascript">

VUI.use('Form',function(){
	var url = ctx + 'updateUserPassword_backuser.do';
	var form = new VUI.Form({formId:'baseForm'});
	
	$('#btnUpdate').click(function(){
		modifyPswd();	
	});
	$('#btnCancel').click(function(){
		hide();
	});
	
	function hide() {
		top.hideModifyPwsd();
	}
	
	function modifyPswd() {
		form.submit({
			url:url
			,onSubmit:function(data) {
				var r = this.check();
				if(r) {
					data.oldPswd = faultylabs.MD5(data.oldPswd);
					data.newPswd = faultylabs.MD5(data.newPswd);
					data.newPswd2 = faultylabs.MD5(data.newPswd2);
				}
				return r;
			}
			,success:function(e) {
				Action.execResult(e,function(){
					hide();
					alert('密码修改成功,请重新登录');
					top.logout();
				});
			}
		});
		
	}
});

function compareSamePswd(val) {
	return (val == $('#newPswdInput').val());
}
</script>
</body>
</html>